from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
# from users.utils import BaseModel
from mlh.utils.models import UserBaseModel, BaseModel


class User(AbstractUser):
    avatar_url = models.CharField(verbose_name='头像地址', max_length=256)
    nick_name = models.CharField(max_length=20, verbose_name='昵称')
    mobile = models.CharField(max_length=11, verbose_name='手机号', unique=True)

    # followed = models.ManyToManyField(to='self', symmetrical=False, related_name='followers')
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.id


class UserDetail(models.Model):
    user = models.OneToOneField(to='User',related_name="detail")
    birthday = models.DateField(verbose_name='生日', null=True, blank=True)
    gender = models.CharField(verbose_name='性别', max_length=20, null=True, blank=True)
    real_name = models.CharField(verbose_name='真实姓名', max_length=20, null=True, blank=True)
    web_site = models.CharField(verbose_name='个人网站', max_length=256, null=True, blank=True)
    address = models.CharField(verbose_name='地址', max_length=50, null=True, blank=True)
    hometown = models.CharField(verbose_name='家乡', max_length=50, null=True, blank=True)
    city = models.CharField(verbose_name='现居城市', max_length=20, null=True, blank=True)
    introduce = models.TextField(verbose_name='个人简介', max_length=1024, null=True, blank=True)
    technology = models.TextField(verbose_name='技术', max_length=1024, null=True, blank=True)
    sophistication=models.CharField(verbose_name="完善度",max_length=20, null=True, blank=True)
    class Meta:
        db_table = 'tb_user_detail'
        verbose_name = '用户详情'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.user.id


class School(models.Model):
    user = models.OneToOneField(to='User')
    school_name = models.CharField(verbose_name='毕业学校', max_length=64, null=True, blank=True)
    professional = models.CharField(verbose_name='所学专业', max_length=128, null=True, blank=True)

    class Meta:
        db_table = 'tb_school'
        verbose_name = '学校'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.school_name


class Company(models.Model):
    user = models.OneToOneField(to='User')
    company = models.CharField(verbose_name='所在公司', max_length=128, null=True, blank=True)
    profession = models.CharField(verbose_name='职业', max_length=128, null=True, blank=True)

    class Meta:
        db_table = 'tb_company'
        verbose_name = '公司'
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s" % self.company


class Exp(UserBaseModel):
    user = models.ForeignKey(to='User',related_name="exp",on_delete=models.CASCADE,null=True,blank=True)
    work_city = models.CharField(verbose_name='工作城市', max_length=20,null=True,blank=True)
    exp_technology = models.CharField('相关技术', max_length=256,null=True,blank=True)
    job_description = models.CharField('职位描述', max_length=512, null=True,blank=True)
    exp_company = models.CharField(verbose_name='所在公司', max_length=128, null=True, blank=True)
    exp_profession = models.CharField(verbose_name='职业', max_length=128, null=True, blank=True)

    class Meta:
        db_table = 'tb_exp'
        verbose_name = '工作经历'
        ordering = ['-start_time']

    def __str__(self):
        return "%s" % self.job_description


class Education(UserBaseModel):
    user = models.ForeignKey(to='User',related_name="edu",on_delete=models.CASCADE,null=True,blank=True)
    background = models.CharField(verbose_name='学历', max_length=16, null=True,blank=True)
    edu_technology = models.CharField('相关技术', max_length=256, null=True,blank=True)
    achievements = models.CharField('取得成就', max_length=128, null=True,blank=True)
    edu_school = models.CharField(verbose_name='毕业学校', max_length=64, null=True, blank=True)
    edu_professional = models.CharField(verbose_name='所学专业', max_length=128, null=True, blank=True)
    class Meta:
        db_table = 'tb_education'
        verbose_name = '教育经历'
        ordering = ['-start_time']

    def __str__(self):
        return "%s" % self.edu_background


class Dynamics(BaseModel):
    user = models.ForeignKey(to='User', related_name="dynamics", on_delete=models.CASCADE)
    # 0 --- 我的回答
    # 1 --- 我的提问
    # 2 --- 我的分享
    # 3 --- 我的关注
    # 4 --- 我的收藏
    # 5 --- 浏览记录
    title = models.CharField(verbose_name='标题', max_length=128, null=True, blank=True)
    category = models.IntegerField(verbose_name='动态分类')
    content = models.TextField(verbose_name='动态内容', max_length=1024)
    label = models.CharField(verbose_name='动态标签', max_length=128, null=True, blank=True)
    # 动态相关的内容的逻辑id,用于查询当前回答问题的关注和回答数
    contact_id = models.IntegerField(default=-1, verbose_name='动态分类')

    class Meta:
        db_table = "tb_dynamics"
        verbose_name = '个人动态'
        ordering = ['-create_time']
